home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
APC & TCP 4
/
APC & TCP 4.iso
/
games
/
publicdomain
/
a
/
attacks
/
sources
/
thinker.mod
< prev
next >
Wrap
Text File
|
1994-05-14
|
39KB
|
972 lines
IMPLEMENTATION MODULE thinker;
(*$R-V-*) (* Range checking OFF, overflow checking OFF *)
(* This module handles all the routines necessary for the computer to *)
(* to play. It also has some routines that are convenient for checking *)
(* to see if the human player screwed up or not. *)
FROM attacksgraphics
IMPORT ChangePointer, DrawSquare, mywindowptr;
FROM header
IMPORT state, movetype, boardrange, boardtype, playertype, squaretype,
allmovestype, difficulty, pointercode, gameover, currentpointer,
backedup, maxmovetypemoves;
FROM mdgenerallib
IMPORT RealRandom, MyPause;
FROM Intuition
IMPORT IDCMPFlags, IntuiMessagePtr, MENUNUM, ITEMNUM;
FROM Ports
IMPORT GetMsg, ReplyMsg;
FROM RandomNumbers
IMPORT Random;
FROM TermInOut
IMPORT WriteString, WriteLn, WriteCard, WriteInt;
CONST
winnumber = 100; (* This is number returned for a WIN. *)
losenumber = -100; (* This one's for a LOSE. *)
ranpick = 0.1; (* This tells how smart it is for diff *)
(* level 2. *)
maxmoves = 400; (* The maximun number of moves genera- *)
(* ted per level. *)
numwhich = 5; (* Tells how many guesses the computer *)
(* gets when doing difficulty 2. *)
VAR
interrupt : BOOLEAN; (* When this is TRUE, then the compu- *)
(* ter's move is to be aborted. *)
imessageptr : IntuiMessagePtr; (* Points to an intuimessage *)
(************************************************************************)
PROCEDURE OtherPlayer (player : playertype) : playertype;
(* Simply returns the other player *)
BEGIN
IF player = red THEN
RETURN blue;
END;
RETURN red;
END OtherPlayer;
(************************************************************************)
PROCEDURE LegalMove (move : movetype) : BOOLEAN;
(* This simply checks to see if the given move is a valid move, con- *)
(* sidering the current state of the game. It is NOT assumed that *)
(* the initial component of the move is valid. It does NOT assume *)
(* both of the move components are valid locations. But it does as- *)
(* sume that the board has been properly initialized so that the outer *)
(* edges are blocks. It operates using the global variable, state. *)
VAR
legal : BOOLEAN;
checkx, checky : boardrange; (* used to see if moves are in range *)
BEGIN
legal := FALSE;
IF (state.board[move.fromX, move.fromY] = state.turn) AND
(state.board[move.toX,move.toY] = empty) THEN
IF move.toX > move.fromX THEN
checkx := move.toX - move.fromX;
ELSE checkx := move.fromX - move.toX;
END;
IF move.toY > move.fromY THEN
checky := move.toY - move.fromY;
ELSE checky := move.fromY - move.toY;
END;
IF (checkx < 3) AND (checky < 3) THEN
legal := TRUE;
END;
END;
RETURN legal;
END LegalMove;
(**************************************************************************)
PROCEDURE FindAllMoves (VAR board : boardtype; player : playertype;
VAR moves : allmovestype);
(* This procedure finds all the possible moves for player in the posi- *)
(* tion of the given board. The resultant moves are stored in the vari- *)
(* able, moves. If there are no moves possible, then moves.nummoves = 0. *)
(* *)
(* INPUT *)
(* board Of boardtype. It describes the state *)
(* of the board in question. *)
(* *)
(* player This tells which side (player) this *)
(* procedure checks the moves for. *)
(* *)
(* OUTPUT *)
(* moves The data structure that holds all the *)
(* moves. *)
VAR
i, j : boardrange;
BEGIN
moves.nummoves := 0;
FOR i := 1 TO 7 DO FOR j := 1 TO 7 DO
IF board[i,j] = player THEN
IF (moves.nummoves < maxmoves) AND (board[i-2,j-2] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 2;
moves.moves[moves.nummoves].toY := j - 2;
END;
IF (moves.nummoves < maxmoves) AND (board[i-2,j-1] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 2;
moves.moves[moves.nummoves].toY := j - 1;
END;
IF (moves.nummoves < maxmoves) AND (board[i-2,j] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 2;
moves.moves[moves.nummoves].toY := j;
END;
IF (moves.nummoves < maxmoves) AND (board[i-2,j+1] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 2;
moves.moves[moves.nummoves].toY := j + 1;
END;
IF (moves.nummoves < maxmoves) AND (board[i-2,j+2] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 2;
moves.moves[moves.nummoves].toY := j + 2;
END;
IF (moves.nummoves < maxmoves) AND (board[i-1,j-2] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 1;
moves.moves[moves.nummoves].toY := j - 2;
END;
IF (moves.nummoves < maxmoves) AND (board[i-1,j-1] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 1;
moves.moves[moves.nummoves].toY := j - 1;
END;
IF (moves.nummoves < maxmoves) AND (board[i-1,j] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;
moves.moves[moves.nummoves].fromY := j;
moves.moves[moves.nummoves].toX := i - 1;
moves.moves[moves.nummoves].toY := j;
END;
IF (moves.nummoves < maxmoves) AND (board[i-1,j+1] = empty) THEN
IF moves.nummoves = maxmovetypemoves THEN
RETURN;
END;
INC(moves.nummoves);
moves.moves[moves.nummoves].fromX := i;